package com.jeesite.modules.jydq.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.jydq.entity.JydqProductComment;
import com.jeesite.modules.jydq.service.JydqProductCommentService;

/**
 * 商品评论表Controller
 * @author dong
 * @version 2025-03-20
 */
@Controller
@RequestMapping(value = "${adminPath}/jydq/productComment")
public class JydqProductCommentController extends BaseController {

	@Autowired
	private JydqProductCommentService jydqProductCommentService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public JydqProductComment get(String id, boolean isNewRecord) {
		return jydqProductCommentService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
//	@RequiresPermissions("jydq:productComment:view")
	@RequestMapping(value = {"list", ""})
	public String list(JydqProductComment jydqProductComment, Model model) {
		model.addAttribute("jydqProductComment", jydqProductComment);
		return "modules/jydq/jydqProductCommentList";
	}
	
	/**
	 * 查询列表数据
	 */
//	@RequiresPermissions("jydq:productComment:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<JydqProductComment> listData(JydqProductComment jydqProductComment, HttpServletRequest request, HttpServletResponse response) {
		jydqProductComment.setPage(new Page<>(request, response));
		Page<JydqProductComment> page = jydqProductCommentService.findPage(jydqProductComment);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
//	@RequiresPermissions("jydq:productComment:view")
	@RequestMapping(value = "form")
	public String form(JydqProductComment jydqProductComment, Model model) {
		model.addAttribute("jydqProductComment", jydqProductComment);
		return "modules/jydq/jydqProductCommentForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("jydq:productComment:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated JydqProductComment jydqProductComment) {
		jydqProductCommentService.save(jydqProductComment);
		return renderResult(Global.TRUE, text("保存商品评论表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("jydq:productComment:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(JydqProductComment jydqProductComment) {
		jydqProductCommentService.delete(jydqProductComment);
		return renderResult(Global.TRUE, text("删除商品评论表成功！"));
	}
	
}